#!/sbin/openrc-run

description="XMPP puppeteering gateway"

instance_name="${RC_SVCNAME#*.}"
instance_name="${instance_name:-slidge}"

: ${SLIDGE_CONFIG:="/etc/slidge/$instance_name.conf"}
export SLIDGE_CONFIG

: "${output_log:=/var/log/slidge/$instance_name.log}"
: "${error_log:=/var/log/slidge/$instance_name.log}"

command=/usr/bin/slidge
command_background="yes"
command_user="slidge:slidge"
pidfile="/run/${RC_SVCNAME}.pid"
directory="/var/lib/slidge"

required_files="$SLIDGE_CONFIG"

depend() {
	need localmount net
	after firewall jabber-server
	use dns
}

start_pre() {
	[ -n "$output_log" ] && checkpath -q -f -m 0640 \
		-o "$command_user" "$output_log"

	[ -n "$error_log" ] && checkpath -q -f -m 0640 \
		-o "$command_user" "$error_log"

	checkpath -q -f -m 0640 -o "$command_user" "$SLIDGE_CONFIG"
	checkpath -q -d -m 0750 -o "$command_user" "$directory"
}
